<template>
  <div class="wrapper"
       v-if="swiperShow">
    <swiper :options="swiperOption">
      <swiper-slide v-for="item of list"
                    :key="item.id">
        <img class="swiper-img"
             :src="item.imgUrl" />
      </swiper-slide>
      <div class="swiper-pagination"
           slot="pagination"></div>
    </swiper>
  </div>
</template>

<script>
export default {
  name: 'HomeSwiper',
  data () {
    return {
      swiperOption: {
        pagination: '.swiper-pagination', // 轮播点
        loop: true // 循环
      }
    }
  },
  props: {
    list: {
      type: Array
    }
  },
  computed: {
    swiperShow () {
      return this.list.length
    }
  }
}

</script>

<style lang="stylus" scoped>
.wrapper >>>.swiper-pagination-bullet // scoped表示样式只作用当前组件,不做用于swiper组件,可以用三个箭头穿刺到达内层组件
  background #fff
.wrapper // 多加这个类的原因是图片如果没有加载成功会导致下面的元素占据图片位置,图片加载会有抖动,这样做会先占据图片大小的位置
  overflow hidden
  width 100%
  height 0
  padding-bottom 40%
  .swiper-img
    width 100%
    height 3rem
</style>
